package com.googlecode.mvcguice;

import com.google.inject.Inject;
import com.googlecode.mvcguice.action.Action;
import com.googlecode.mvcguice.action.Actions;
import com.googlecode.mvcguice.routing.ReverseRouter;

/**
 * Base controller class.
 * 
 * Provides set of utility methods for creating actions.
 * 
 * @author Andrey Vityuk
 */
public abstract class Controller {
	@Inject
	ReverseRouter reverseRouter;

	protected final Action render() {
		return Actions.render();
	}

	protected final Action render(Object value) {
		return Actions.render(value);
	}

	protected final Action render(Iterable<?> values) {
		return Actions.render(values);
	}

	protected final Action render(String name, Object value) {
		return Actions.render(name, value);
	}

	protected final Action render(Model model) {
		return Actions.render(model);
	}

	protected final Action send(String content) {
		return Actions.send(content);
	}

	protected final Action redirect(String location) {
		return Actions.redirect(location);
	}

	protected final <T> T urlFor(final Class<T> controller) {
		return redirect(controller);
	}

	protected final <T> T redirect(final Class<T> controller) {
		return reverseRouter.redirect(controller);
	}
}
